Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "H+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};


function getHourX(start, end) {
    var _end = new Date(end);
    end = new Date(end);
    _end.setMinutes(0);
    _end.setSeconds(0);
    _end.setMilliseconds(0);
    //去除整点00:00:00时多算的一天
    if (_end.getTime() == end.getTime()) {
        end.setMinutes(-60);
    }
    end.setMinutes(0);
    end.setSeconds(0);
    end.setMilliseconds(0);


    var time = new Date(start);
    time.setMinutes(-60);
    time.setSeconds(0);
    time.setMilliseconds(0);
    var j = 0, arr = [];
    while (time.getTime() < end.getTime()) {
        time.setMinutes(time.getMinutes() + 60);
        var _time = new Date(time).Format("yyyy-MM-dd HH");
        var __time = new Date(time).Format("HH");
        arr.push(__time);
        _time = _time + ":00:00";
        time = new Date(_time);
    }
    return arr;
}

function getDayX(start, end) {
    var _end = new Date(end);
    end = new Date(end);
    _end.setHours(0);
    _end.setMinutes(0);
    _end.setSeconds(0);
    _end.setMilliseconds(0);
    //去除整点00:00:00时多算的一天
    if (_end.getTime() == end.getTime()) {
        end.setHours(-24)
    }
    end.setHours(0);
    end.setMinutes(0);
    end.setSeconds(0);
    end.setMilliseconds(0);

    var time = new Date(start);
    time.setHours(-24);
    time.setMinutes(0);
    time.setSeconds(0);
    time.setMilliseconds(0);

    var j = 0, arr = [];
    while (time.getTime() < end.getTime()) {
        time.setHours(time.getHours() + 24);
        var _time = new Date(time).Format("yyyy-MM-dd");
        arr.push(_time);
        _time = _time + " 00:00:00";
        time = new Date(_time);
    }
    return arr;
}

function getMonthX(start, end) {
    var _end = new Date(end);
    end = new Date(end);
    //去除月第一天00:00:00时多算的一月
    end.setDate(1);
    end.setHours(0);
    end.setMinutes(0);
    end.setSeconds(0);
    end.setMilliseconds(0);
    if (end.getTime() == _end.getTime()) {
        end = addMonth(end, -1)
    }

    var time = new Date(start);
    time.setDate(1);
    time.setHours(0);
    time.setMinutes(0);
    time.setSeconds(0);
    time.setMilliseconds(0);
    time = addMonth(time, -1);
    var j = 0, arr = [];
    while (time.getTime() < end.getTime()) {
        time.setMonth(time.getMonth() + 1);
        var _time = new Date(time).Format("yyyy-MM");
        arr.push(_time);
        _time = _time + "-01 00:00:00";
        time = new Date(_time);
    }
    return arr;
}

function dateToDate(date) {
    var sDate = new Date();
    if (typeof date == 'object'
        && typeof new Date().getMonth == "function"
    ) {
        sDate = date;
    }
    else if (typeof date == "string") {
        var arr = date.split('-');
        if (arr.length == 3) {
            sDate = new Date(arr[0] + '-' + arr[1] + '-' + arr[2]);
        }
    }

    return sDate;
}

function addMonth(date, num) {
    num = parseInt(num);
    var sDate = dateToDate(date);

    var sYear = sDate.getFullYear();
    var sMonth = sDate.getMonth() + 1;
    var sDay = sDate.getDate();

    var eYear = sYear;
    var eMonth = sMonth + num;
    var eDay = sDay;
    while (eMonth > 12) {
        eYear++;
        eMonth -= 12;
    }

    eDate = new Date(eYear, eMonth - 1, eDay);
    return eDate;
}

function addDay(date, n) {
    var _date = new Date(date);
    _date.setHours(n * 24);
    _date.setMinutes(0);
    _date.setSeconds(0);
    _date.setMilliseconds(0);
    return _date;
}

function addHour(date, n) {
    var _date = new Date(date);
    _date.setMinutes(n * 60);
    _date.setSeconds(0);
    _date.setMilliseconds(0);
    return _date;
}